package graduate.wangyaqi.Question;

import graduate.wangyaqi.OnlyQuestions.OnlyQuestions;
import graduate.wangyaqi.OnlyQuestions.OnlyQuestionsRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.Optional;

@Service
public class QuestionService {
    @Resource
    private QuestionRepository questionRepository;

    //保存数据
    @Transactional
    public void save(Question question) {
        questionRepository.save(question);
    }

    //删除数据
    @Transactional
    public void delete(long id) {
        questionRepository.deleteById(id);
    }

    //查询数据
    @Transactional
    public Iterable<Question> getAll() {
        Iterable<Question> questions = questionRepository.findAll();
        return questions;
    }

    @Transactional
    public Optional<Question> findById(Long aLong){
        return questionRepository.findById(aLong);
    };
}
